<template>
  <div class="exchange-entry">
    <div class="entry-card" @click="goToExchangeShop">
      <div class="entry-icon">
        <i class="el-icon-coin"></i>
      </div>
      <div class="entry-content">
        <h3>积分兑换</h3>
        <p>用积分兑换精美商品</p>
        <div class="user-points" v-if="userPoints !== null">
          <span>我的积分：{{ userPoints }}</span>
        </div>
      </div>
      <div class="entry-arrow">
        <i class="el-icon-arrow-right"></i>
      </div>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'ExchangeEntry',
  data() {
    return {
      userPoints: null
    }
  },
  mounted() {
    this.loadUserPoints()
  },
  methods: {
    async loadUserPoints() {
      try {
        const user = JSON.parse(localStorage.getItem('user'))
        if (user && user.id) {
          const response = await request.get(`/api/member/points/available/${user.id}`)
          if (response.code === '200') {
            this.userPoints = response.data || 0
          }
        }
      } catch (error) {
        console.error('加载用户积分失败:', error)
      }
    },
    
    goToExchangeShop() {
      this.$router.push('/exchange/shop')
    }
  }
}
</script>

<style scoped>
.exchange-entry {
  margin: 20px 0;
}

.entry-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.entry-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.entry-icon {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
}

.entry-icon i {
  font-size: 30px;
  color: #ffffff;
}

.entry-content {
  flex: 1;
  color: #ffffff;
}

.entry-content h3 {
  margin: 0 0 5px 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.entry-content p {
  margin: 0 0 10px 0;
  opacity: 0.9;
  font-size: 0.95rem;
}

.user-points {
  font-size: 0.9rem;
  opacity: 0.8;
}

.entry-arrow {
  color: #ffffff;
  font-size: 1.2rem;
  opacity: 0.8;
}

@media (max-width: 768px) {
  .entry-card {
    padding: 15px;
  }
  
  .entry-icon {
    width: 50px;
    height: 50px;
    margin-right: 15px;
  }
  
  .entry-icon i {
    font-size: 24px;
  }
  
  .entry-content h3 {
    font-size: 1.2rem;
  }
}
</style> 